package com.wuh.service.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wuh.mapper.TeacherMapper;
import com.wuh.model.Teacher;
import com.wuh.service.TeacherService;

@Service
public class TeacherServiceImpl implements TeacherService {

	@Autowired
    private TeacherMapper teacherMapper;
	
	@Override
	public Teacher login(Teacher teacher) {
		// TODO Auto-generated method stub
		return teacherMapper.login(teacher);
	}

	@Override
	public Integer register(Teacher teacher) {
		// TODO Auto-generated method stub
		teacher.setCreate_time(new Date());
		return teacherMapper.register(teacher);
	}

	@Override
	public void editTeacherCaslteNum(Integer teacher_id) {

		teacherMapper.editTeacherCaslteNum(teacher_id);
	}

	@Override
	public int editTeacher(Teacher teacher) {
		// TODO Auto-generated method stub
		return teacherMapper.editTeacher(teacher);
	}

	@Override
	public Teacher getTeacherById(Integer teacher_id) {
		// TODO Auto-generated method stub
		return teacherMapper.getTeacherById(teacher_id);
	}

	@Override
	public int editPasswordById(Teacher techer) {
		// TODO Auto-generated method stub
		return teacherMapper.editPasswordById(techer);
	}

	@Override
	public List<Teacher> getTeachers() {
		return teacherMapper.getTeachers();
	}

	@Override
	public PageInfo<Teacher> getTeachers(Teacher teacher) {
		// TODO Auto-generated method stub
		PageHelper.startPage(teacher.getPageNum(), teacher.getPageSize());
		List<Teacher> list = teacherMapper.getTeachers(teacher);
		PageInfo<Teacher> pageInfo = new PageInfo<Teacher>(list);

		System.out.println(pageInfo);
		return pageInfo;
	}

	/**
	 * 批量删除teacher
	 */
	@Override
	@Transactional //事务注解
	public int delTeachers(Integer[] ids) {
		// TODO Auto-generated method stub
		int flag = 0;
		for(Integer id : ids) {
			flag = teacherMapper.delTeacherById(id);
		}

		return flag;
	}

	/**
	 * 批量冷冻teacher
	 */
	@Override
	@Transactional //事务注解
	public int freezeTeachers(Integer[] ids) {
		// TODO Auto-generated method stub
		int flag = 0;
		for(Integer id : ids) {
			flag = teacherMapper.freezeTeacherById(id);
		}

		return flag;
	}

	/**
	 * 批量解冻teacher
	 */
	@Override
	@Transactional //事务注解
	public int unfreezeTeachers(Integer[] ids) {
		// TODO Auto-generated method stub
		int flag = 0;
		for(Integer id : ids) {
			flag = teacherMapper.unfreezeTeacherById(id);
		}

		return flag;
	}

	@Override
	public int addTeacher(Teacher teacher) {
		// TODO Auto-generated method stub
		teacher.setCreate_time(new Date());
		return teacherMapper.addTeacher(teacher);
	}


    /**
     * 获取所有的teacher信息用于公开课预加载数据做查询条件参数
     *
     * @return
     */
    public List<Teacher> schTeachers(){
    	return  teacherMapper.getTeachers();
	}

}
